package cn.adviceclient.features.value;

import cn.adviceclient.utility.render.ColorUtils;

import java.awt.*;

public class ColorSetting extends AbstractSetting<Color> {
    private float hue = 0;
    private float saturation = 1;
    private float brightness = 1;
    private float alpha = 1;
    private boolean rainbow = false;

    public ColorSetting(String name, String description, Color value) { super(name,description,value);}
    public ColorSetting(String name, String description, Color value, java.util.function.Supplier<Boolean> visible) { super(name,description,value,visible);}

    public Color getValue() {
        return ColorUtils.applyOpacity(Color.getHSBColor(hue, saturation, brightness), alpha);
    }
    public Color get() {
        return ColorUtils.applyOpacity(Color.getHSBColor(hue, saturation, brightness), alpha);
    }

    public void setValue(Color color) {
        float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null);
        hue = hsb[0];
        saturation = hsb[1];
        brightness = hsb[2];
        alpha = color.getAlpha() / 255.0f;
    }

    public float getHue() {
        return hue;
    }

    public void setHue(float hue) {
        this.hue = hue;
    }

    public float getSaturation() {
        return saturation;
    }

    public void setSaturation(float saturation) {
        this.saturation = saturation;
    }

    public float getBrightness() {
        return brightness;
    }

    public void setBrightness(float brightness) {
        this.brightness = brightness;
    }

    public float getAlpha() {
        return alpha;
    }

    public void setAlpha(float alpha) {
        this.alpha = alpha;
    }

    public boolean isRainbow() {
        return rainbow;
    }

    public void setRainbow(boolean rainbow) {
        this.rainbow = rainbow;
    }
}
